//
// Created on 2025/9/14.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

// napi_init.cpp
#include "napi/native_api.h"

static napi_value NativeAdd(napi_env env, napi_callback_info info) {
    napi_value args;
    size_t argc = 2;
    napi_get_cb_info(env, info, &argc, &args, nullptr, nullptr);

    int32_t a, b;
    napi_get_value_int32(env, args, &a);
    napi_get_value_int32(env, args, &b);

    napi_value result;
    napi_create_int32(env, a + b, &result);
    return result;
}

static napi_value Init(napi_env env, napi_value exports) {
    napi_property_descriptor desc = { "add", 0, NativeAdd, 0, 0, 0, napi_default, 0 };
    napi_define_properties(env, exports, 1, &desc);
    return exports;
}

EXTERN_C_START
napi_value NAPI_Module_Register(napi_env env, napi_value exports) {
    return Init(env, exports);
}
EXTERN_C_END